#include "unity.h"
#include "mock_bsp_test_commom.h" // CMock 生成的 mock 头文件
#include "Rt_LUT_Config.h"

// Test instance pointer
static XRt1553B *testInstance;

void setUp(void)
{
    // Initialize test instance before each test
    testInstance = malloc(sizeof(XRt1553B));
    memset(testInstance, 0, sizeof(XRt1553B));
    testInstance->BaseAddress = 0x1000;
}

void tearDown(void)
{
    // Clean up after each test
    free(testInstance);
}

// Helper function to initialize default configuration
void init_default_config()
{
    for (int i = 0; i < 32; i++)
    {
        testInstance->rx_SAcfg[i].valid_data_bytes = 0;
        testInstance->rx_SAcfg[i].mm_mode = XRT53_MM_UNUSE;
        testInstance->rx_SAcfg[i].DataBlock_number = 100;
        testInstance->rx_SAcfg[i].DataBlock_start_ptr = XRT53_DATABLOCK_ADDR(100);

        testInstance->tx_SAcfg[i].valid_data_bytes = 0;
        testInstance->tx_SAcfg[i].mm_mode = XRT53_MM_UNUSE;
        testInstance->tx_SAcfg[i].DataBlock_number = 100;
        testInstance->tx_SAcfg[i].DataBlock_start_ptr = XRT53_DATABLOCK_ADDR(100);

        testInstance->bcst_SAcfg[i].valid_data_bytes = 0;
        testInstance->bcst_SAcfg[i].mm_mode = XRT53_MM_UNUSE;
        testInstance->bcst_SAcfg[i].DataBlock_number = 100;
        testInstance->bcst_SAcfg[i].DataBlock_start_ptr = XRT53_DATABLOCK_ADDR(100);
    }
}

// Test case 1: RX Single Message Mode
void test_Rt_LUT_Config_RX_Single_Msg_Mode(void)
{
    init_default_config();

    // Configure first RX subaddress to single message mode
    testInstance->rx_SAcfg[0].mm_mode = XRT53_MM_SINGLE_MSG;
    testInstance->rx_SAcfg[0].DataBlock_number = 5;

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(0), XRT53_DATABLOCK_ADDR(5));
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(0), XRT53_DATABLOCK_ADDR(5));

    // Expectations for writing control words
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x200); // 0x200为0清零置一后的值
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x200);

    // For other 31 subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    // Similar expectations for TX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }
    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(XRT53_DATABLOCK_ADDR(5), testInstance->rx_SAcfg[0].DataBlock_start_ptr);
}

// Test case 2: RX Double Buffer Mode
void test_Rt_LUT_Config_RX_Double_Buffer_Mode(void)
{
    init_default_config();

    // Configure first RX subaddress to double buffer mode
    testInstance->rx_SAcfg[0].mm_mode = XRT53_MM_DOUBLE_BUFFER;
    testInstance->rx_SAcfg[0].DataBlock_number = 10;

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(0), XRT53_DATABLOCK_ADDR(10));
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(0), XRT53_DATABLOCK_ADDR(10));

    // Expectations for writing control words
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x8200); // 0x8200为0清零置一后的值
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x8200);

    // For other 31 subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    // Similar expectations for TX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(XRT53_DATABLOCK_ADDR(10), testInstance->rx_SAcfg[0].DataBlock_start_ptr);
}

// Test case 3: RX Circular Buffer Mode
void test_Rt_LUT_Config_RX_Circular_Buffer_Mode(void)
{
    init_default_config();

    // Configure first RX subaddress to circular buffer mode
    testInstance->rx_SAcfg[0].mm_mode = XRT53_MM_CIRCULAR_BUFFER;
    testInstance->rx_SAcfg[0].DataBlock_start_ptr = 0x222;
    testInstance->rx_SAcfg[0].valid_data_bytes = 128; // Should map to MM mode 1

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(0), 0x222);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(0), 0x222);

    // Expectations for writing control words (circular buffer with MM mode 1)
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    datalenth_2_MM_mode_ExpectAndReturn(testInstance->rx_SAcfg[0].valid_data_bytes, 1); // 返回1
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x120);    // 设置为mm为1 循环缓冲中断为1
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x120);

    // For other 31 subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    // Similar expectations for TX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(0x222, testInstance->rx_SAcfg[0].DataBlock_start_ptr);
}

// Test case 4: RX Unused Mode (Default)
void test_Rt_LUT_Config_RX_Unused_Mode(void)
{
    init_default_config();

    // All RX subaddresses are already in unused mode by default
    // Expectations for all 32 subaddresses
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    // Similar expectations for TX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);
}

// Test case 5: TX Single Message Mode
void test_Rt_LUT_Config_TX_Single_Msg_Mode(void)
{
    init_default_config();

    // Configure first TX subaddress to single message mode
    testInstance->tx_SAcfg[0].mm_mode = XRT53_MM_SINGLE_MSG;
    testInstance->tx_SAcfg[0].DataBlock_number = 15;

    // Expectations for RX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(0), XRT53_DATABLOCK_ADDR(15));
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(0), XRT53_DATABLOCK_ADDR(15));

    // Expectations for writing control words
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x4000);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x4000);

    // For other 31 TX subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(XRT53_DATABLOCK_ADDR(15), testInstance->tx_SAcfg[0].DataBlock_start_ptr);
}

// Test case 6: TX Circular Buffer Mode
void test_Rt_LUT_Config_TX_Circular_Buffer_Mode(void)
{
    init_default_config();

    // Configure first TX subaddress to circular buffer mode
    testInstance->tx_SAcfg[0].mm_mode = XRT53_MM_CIRCULAR_BUFFER;
    testInstance->tx_SAcfg[0].DataBlock_start_ptr = 0x300;
    testInstance->tx_SAcfg[0].valid_data_bytes = 512; // Should map to MM mode 2

    // Expectations for RX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(0), 0x300);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(0), 0x300);

    // Expectations for writing control words (circular buffer with MM mode 2)
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    datalenth_2_MM_mode_ExpectAndReturn(testInstance->tx_SAcfg[0].valid_data_bytes, 2); // 返回1
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x2800);   // mm=2
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x2800);

    // For other 31 TX subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(0x300, testInstance->tx_SAcfg[0].DataBlock_start_ptr);
}

// Test case 7: TX Unused Mode (Default)
void test_Rt_LUT_Config_TX_Unused_Mode(void)
{
    init_default_config();

    // Expectations for RX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);
}

// Test case 8: BCST Single Message Mode
void test_Rt_LUT_Config_BCST_Single_Msg_Mode(void)
{
    init_default_config();

    // Configure first BCST subaddress to single message mode
    testInstance->bcst_SAcfg[0].mm_mode = XRT53_MM_SINGLE_MSG;
    testInstance->bcst_SAcfg[0].DataBlock_number = 20;

    // Expectations for RX and TX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(0), XRT53_DATABLOCK_ADDR(20));
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(0), XRT53_DATABLOCK_ADDR(20));

    // Expectations for writing control words
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x10);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x10);

    // For other 31 BCST subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(XRT53_DATABLOCK_ADDR(20), testInstance->bcst_SAcfg[0].DataBlock_start_ptr);
}

// Test case 9: BCST Double Buffer Mode
void test_Rt_LUT_Config_BCST_Double_Buffer_Mode(void)
{
    init_default_config();

    // Configure first BCST subaddress to double buffer mode
    testInstance->bcst_SAcfg[0].mm_mode = XRT53_MM_DOUBLE_BUFFER;
    testInstance->bcst_SAcfg[0].DataBlock_number = 25;

    // Expectations for RX and TX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(0), XRT53_DATABLOCK_ADDR(25));
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(0), XRT53_DATABLOCK_ADDR(25));

    // Expectations for writing control words
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x8010);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x8010);

    // For other 31 BCST subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(XRT53_DATABLOCK_ADDR(25), testInstance->bcst_SAcfg[0].DataBlock_start_ptr);
}

// Test case 10: BCST Circular Buffer Mode
void test_Rt_LUT_Config_BCST_Circular_Buffer_Mode(void)
{
    init_default_config();

    // Configure first BCST subaddress to circular buffer mode
    testInstance->bcst_SAcfg[0].mm_mode = XRT53_MM_CIRCULAR_BUFFER;
    testInstance->bcst_SAcfg[0].DataBlock_start_ptr = 0x400;
    testInstance->bcst_SAcfg[0].valid_data_bytes = 1024; // Should map to MM mode 3

    // Expectations for RX and TX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Expectations for writing LUT entries
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(0), 0x400);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(0), 0x400);

    // Expectations for writing control words (circular buffer with MM mode 3)
    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    datalenth_2_MM_mode_ExpectAndReturn(testInstance->bcst_SAcfg[0].valid_data_bytes, 3); // 返回1
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0x0b);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), 0x0b);

    // For other 31 BCST subaddresses, expect unused configuration
    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(0x400, testInstance->bcst_SAcfg[0].DataBlock_start_ptr);
}

// Test case 11: BCST Unused Mode (Default)
void test_Rt_LUT_Config_BCST_Unused_Mode(void)
{
    init_default_config();

    // Expectations for RX subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
    }

    // Similar expectations for BCST subaddresses (all unused)
    for (int i = 0; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);
}

// Test case 12: Mixed Mode Configuration
void test_Rt_LUT_Config_Mixed_Mode(void)
{
    init_default_config();

    // Configure different modes for different subaddresses
    testInstance->rx_SAcfg[0].mm_mode = XRT53_MM_SINGLE_MSG;
    testInstance->rx_SAcfg[0].DataBlock_number = 5;

    testInstance->tx_SAcfg[1].mm_mode = XRT53_MM_CIRCULAR_BUFFER;
    testInstance->tx_SAcfg[1].DataBlock_start_ptr = 0x300;
    testInstance->tx_SAcfg[1].valid_data_bytes = 256; // Should map to MM mode 1

    testInstance->bcst_SAcfg[2].mm_mode = XRT53_MM_DOUBLE_BUFFER;
    testInstance->bcst_SAcfg[2].DataBlock_number = 15;

    // Expectations for RX subaddresses
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(0), XRT53_DATABLOCK_ADDR(5));
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(0), XRT53_DATABLOCK_ADDR(5));

    XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), 0);
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(0), (1 << 9));
    XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(0), (1 << 9));

    for (int i = 1; i < 32; i++)
    {
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_RX(i), XRT53_DATABLOCK_UNUSED);
        XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
        XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_RX_UNUSED_MASK));
    }

    // Expectations for TX subaddresses
    for (int i = 0; i < 32; i++)
    {
        if (i == 1)
        {
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), 0x300);
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), 0x300);

            XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0);
            datalenth_2_MM_mode_ExpectAndReturn(testInstance->tx_SAcfg[i].valid_data_bytes, 1); // 返回1
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0x2400);   // mm=1
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), 0x2400);
        }
        else
        {
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_TX(i), XRT53_DATABLOCK_UNUSED);
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_TX(i), XRT53_DATABLOCK_UNUSED);
            XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_TX_UNUSED_MASK));
        }
    }

    // Expectations for BCST subaddresses
    for (int i = 0; i < 32; i++)
    {
        if (i == 2)
        {
            
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(2), XRT53_DATABLOCK_ADDR(15));
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(2), XRT53_DATABLOCK_ADDR(15));
            XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(2), 0);
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(2), 0x8010);
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(2), 0x8010);
        }
        else
        {
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_BCST(i), XRT53_DATABLOCK_UNUSED);
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_BCST(i), XRT53_DATABLOCK_UNUSED);
            XRt1553B_ReadMem_ExpectAndReturn(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), 0xFFFF);
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_A_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
            XRt1553B_WriteMem_Expect(testInstance->BaseAddress, XRT53_LUT_B_SACW(i), (0xFFFF & XRT53_SACW_BCST_UNUSED_MASK));
        }
    }

    // Call the function under test
    Rt_LUT_Config(testInstance);

    // Verify results
    TEST_ASSERT_EQUAL_HEX32(XRT53_DATABLOCK_ADDR(5), testInstance->rx_SAcfg[0].DataBlock_start_ptr);
    TEST_ASSERT_EQUAL_HEX32(0x300, testInstance->tx_SAcfg[1].DataBlock_start_ptr);
    TEST_ASSERT_EQUAL_HEX32(XRT53_DATABLOCK_ADDR(15), testInstance->bcst_SAcfg[2].DataBlock_start_ptr);
}